package com.health.mapp.service;

import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;


/**
 * @author  yuchong
 */
public class PartnerLogin extends HttpServlet {
    /**
     * @see HttpServlet#HttpServlet()
     */

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		ServletContext servletContext = request.getSession().getServletContext();

		ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        String businessCode = "-1002";
        String userPhone = request.getParameter("user_phone");

        if (StringUtils.isNotBlank(userPhone)) {
            JSONObject json=null;//JSONObject.fromObject(responseStr);
           
            String errorCode =json.getString("errorCode");

            if(StringUtils.isNotBlank(errorCode)&&("0".equals(errorCode))){
                JSONObject user=JSONObject.fromObject(json.get("user"));
                String userId = json.getString("userId");
                response.sendRedirect("/shouerwap/pages/home_new.html?random="+userId);
            }else{
                response.sendRedirect("/shouerwap/pages/home_new.html");
            }

        }else{
            response.sendRedirect("/shouerwap/pages/home_new.html");

        }
		
	}
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}
	
	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
	}

	private void mian() {
		
		
		// TODO Auto-generated method stub

	}
}
